import request from '@/utils/request'

// 查询订单主表列表
export function listOrders(query) {
    return request({
        url: '/dashboard/orders/list',
        method: 'get',
        params: query
    })
}

// 查询所有订单主表列表 (不分页)
export function statistical(query) {
    return request({
        url: '/dashboard/orders/statistics',
        method: 'get',
        params: query
    })
}

// 获取订单状态数量
export function getOrderStatusCount(query) {
    return request({
        url: '/dashboard/orders/status-count',
        method: 'get',
        params: query
    })
}

// 查询订单主表详细
export function getOrders(id) {
    return request({
        url: '/dashboard/orders/' + id,
        method: 'get'
    })
}

// 新增订单主表
export function addOrders(data) {
    return request({
        url: '/dashboard/orders',
        method: 'post',
        data: data
    })
}

// 修改订单主表
export function updateOrders(data) {
    return request({
        url: '/dashboard/orders',
        method: 'put',
        data: data
    })
}

// 切换订单完成状态
export function switchCompletionStatus(id, completionStatus) {
    return request({
        url: '/dashboard/orders/completion-status/' + id,
        method: 'put',
        data: { completionStatus }
    })
}

// 删除订单主表
export function delOrders(id) {
    return request({
        url: '/dashboard/orders/' + id,
        method: 'delete'
    })
}

// 上传订单需求文档
export function uploadOrderRequirement(data) {
    return request({
        url: '/dashboard/orders/requirement/upload',
        method: 'post',
        data: data
    })
}

// 上传订单附件
export function uploadOrderAttachment(data) {
    return request({
        url: '/dashboard/orders/attachment/upload',
        method: 'post',
        data: data
    })
}

// 获取订单需求文档列表
export function listOrderRequirements(orderId) {
    return request({
        url: '/dashboard/orders/requirement/list/' + orderId,
        method: 'get'
    })
}

// 获取订单附件列表
export function listOrderAttachments(orderId) {
    return request({
        url: '/dashboard/orders/attachment/list/' + orderId,
        method: 'get'
    })
}

// 新增退款
export function addRefund(data) {
    return request({
        url: '/dashboard/refund',
        method: 'post',
        data: data
    })
}

// 获取所有技术等级列表
export function listAllSkillLevels() {
    return request({
        url: '/dashboard/levels/all',
        method: 'get'
    })
}

// 查询所有程序类型
export function listAllSkills(query) {
    return request({
        url: '/dashboard/skills/list',
        method: 'get',
        params: query
    })
}

// 预测旧订单价格
export function predictOldOrderPrice(data) {
    return request({
        url: '/dashboard/oldOrders/predict',
        method: 'post',
        data: data
    })
}

// 上传收款图片
export function uploadReceiptImage(data) {
    return request({
        url: '/dashboard/orders/receipt-images/upload',
        method: 'post',
        data: data
    })
}

// 技术交付 - 修改订单状态为未过售后期
export function updateOrderStatusCloseSucceed(id) {
    return request({
        url: '/dashboard/orders/updateOrderStatusCloseSucceed/' + id,
        method: 'get'
    })
}

// 客户确认 - 修改订单状态为已完成
export function updateOrderStatusSucceed(id) {
    return request({
        url: '/dashboard/orders/updateOrderStatusSucceed/' + id,
        method: 'get'
    })
}

// 上传需求图片
export function uploadDemandImage(data) {
    return request({
        url: '/dashboard/orders/demand-images/upload',
        method: 'post',
        data: data
    })
}

// 查询所有订单列表（用于下拉框选择）
export function selectOrderList() {
    return request({
        url: '/dashboard/orders/list',
        method: 'get',
        params: {
            pageNum: 1,
            pageSize: 10000  // 获取所有订单
        }
    })
}

// 查询售后跟单可选订单列表（下拉框使用，根据角色权限过滤）
export function getAfterSaleOrderOptions() {
    return request({
        url: '/dashboard/orders/afterSaleOrderOptions',
        method: 'get'
    })
}
